package controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/6/22
 * \* Time: 14:38
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //先找到当前用户的会话，然后把当前用户会话的信息删除、
        HttpSession session = req.getSession(false);
        if(session == null){
            //用户没有登录，则不用注销
            resp.getWriter().write("当前用户尚未登录，无法注销");
        }
        session.removeAttribute("user");
        resp.sendRedirect("blog_login.html");
    }
}
